<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Captcha_Model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->helper('captcha');
    }

    function login() {
        $capcay = $this->get_captcha();
        $this->session->set_userdata(array(
            "captcha_code_login" => $capcay['word'],
            "captcha_image_login" => $capcay['image']
        ));
        return $capcay;
    }

    function get_captcha() {
        $len = 5;
        $chars = 'ABCEFHKLMNPTXZ2345689'; //'abdefghijkmnqrtyABCDEFGHJKLMNPQRSTUVWXYZ';
        $string = '';

        for ($i = 0; $i < $len; $i++) {
            $pos = rand(0, strlen($chars) - 1);
            $string .= $chars{$pos};
        }

        $config = array(
            'word' => $string,
            'img_path' => './captcha/',
            'img_url' => base_url() . 'captcha/',
            'expiration' => 600,
            'font_path' => './static/fonts/courbd.ttf',
            'img_width' => 170,
            'img_height' => 35,
            'expiration' => 7200
        );

        $result = create_captcha($config);

        return $result;
    }

}